<?php

namespace app\admin\controller\general;

use app\admin\model\AuthRule;
use app\common\controller\BaseAdminController;

class Config extends BaseAdminController
{
    /**
     * 保存配置
     * @return mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function save()
    {
        $data = $this->request->param('row/a');
        if(empty($data)){
           return $this->error('没有数据');
        }
        foreach ($data as $k => $v){
            $row = \app\common\model\Config::where('name',$k)
                ->find();
            if($row){
                $row->value = $v;
                $row->save();
            }else{
                \app\common\model\Config::create([
                    'name' => $k,
                    'value' => $v
                ]);
            }
        }
        return $this->success('保存成功');
    }

}